package com.zinnaworks.smart_cloud_gamepad.popup;

import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.TextView;

import com.zinnaworks.smart_cloud_gamepad.R;

public class TwoLineDialogPopup extends Dialog {

	private TextView titleText;
	private TextView contentText;
	private Button oneBtn;
	private Button twoBtn;
	
	myOnTwoLineClickListener myListener;
	
	 public interface myOnTwoLineClickListener {
	        void onButtonClick(boolean bl);
	    }
	
	public TwoLineDialogPopup(Context context , myOnTwoLineClickListener myListener) {
		super(context ,android.R.style.Theme_Translucent_NoTitleBar_Fullscreen);
		this.myListener = myListener;
	}
	
	public void setDialogText(String popupTitle , String popupPrepearContent)
	{
		titleText.setText(popupTitle);
		contentText.setText(popupPrepearContent);
	}
	
	@Override
    public void onCreate(Bundle savedInstanceState) {
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.popup_2line_2button);
        
        titleText = (TextView) findViewById(R.id.popup_title);
        contentText = (TextView) findViewById(R.id.popup_content);
 
        oneBtn = (Button) findViewById(R.id.retryButton);
        oneBtn.setOnClickListener(new android.view.View.OnClickListener() {
 
            @Override
            public void onClick(View arg0) {
                myListener.onButtonClick(true);
            }
        });
        oneBtn.setOnTouchListener(new View.OnTouchListener() {
			
			@Override
			public boolean onTouch(View paramView, MotionEvent paramMotionEvent) {
				// TODO Auto-generated method stub
				switch (paramMotionEvent.getAction()) {
				case MotionEvent.ACTION_DOWN:
					oneBtn.setTextColor(Color.parseColor("#ffffff"));
					break;
				case MotionEvent.ACTION_UP:
					oneBtn.setTextColor(Color.parseColor("#4f5051"));
					break;
				}
				return false;
			}
		});
        
        twoBtn = (Button) findViewById(R.id.closeButton);
        twoBtn.setOnClickListener(new android.view.View.OnClickListener() {
 
            @Override
            public void onClick(View arg0) {
                myListener.onButtonClick(false);
            }
        });
        twoBtn.setOnTouchListener(new View.OnTouchListener() {
			
			@Override
			public boolean onTouch(View paramView, MotionEvent paramMotionEvent) {
				// TODO Auto-generated method stub
				switch (paramMotionEvent.getAction()) {
				case MotionEvent.ACTION_DOWN:
					twoBtn.setTextColor(Color.parseColor("#ffffff"));
					break;
				case MotionEvent.ACTION_UP:
					twoBtn.setTextColor(Color.parseColor("#4f5051"));
					break;
				}
				return false;
			}
		});
    }
	
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		switch (keyCode) {

		//하드웨어 뒤로가기 버튼에 따른 이벤트 설정
		case KeyEvent.KEYCODE_BACK:
			myListener.onButtonClick(false);
			break;
		}
		return super.onKeyDown(keyCode, event);
	}
}
